import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _isUndefined from "lodash/isUndefined";
import _filter from "lodash/filter";
import _uniqBy from "lodash/uniqBy";
import _pullAllBy from "lodash/pullAllBy";
import _isEmpty from "lodash/isEmpty";

/* eslint-disable no-nested-ternary */
import React, { PureComponent } from 'react';
import { Button, Drawer, Divider } from 'antd';
import { getCurrentOrganizationId, getResponse } from 'utils/utils'; // import { totalRender } from 'utils/renderer';

import intl from 'utils/intl';
import EditorForm from "./Form";
import Permissions from "./PermissionsLov";
import IconsModal from "./Icons";
import CopyMenuTable from "./CopyMenuTable";
import styles from "./index.less?modules";
var viewMessagePrompt = 'ciam.menuConfig.view.message';
var commonPrompt = 'cpaas.common';

var Editor = /*#__PURE__*/function (_PureComponent) {
  _inherits(Editor, _PureComponent);

  var _super = _createSuper(Editor);

  function Editor(props) {
    var _this;

    _classCallCheck(this, Editor);

    _this = _super.call(this, props);
    _this.state = {
      dataSource: {},
      permissionsSelectedRows: [],
      permissionsModalVisible: false,
      permissionsModalDataSource: [],
      permissionsModalPagination: {},
      iconsModalVisible: false,
      copyMenuList: [],
      menuSelectedRowKeys: [],
      relatedRowKeys: [],
      menuLabels: []
    };
    return _this;
  }

  _createClass(Editor, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      //   const { resetFields = e => e } = this.editForm;
      //   resetFields();
      var _this$props = this.props,
          id = _this$props.dataSource.id,
          copyFlag = _this$props.copyFlag,
          _this$props$queryLabe = _this$props.queryLabel,
          queryLabel = _this$props$queryLabe === void 0 ? function (e) {
        return e;
      } : _this$props$queryLabe;

      if (copyFlag) {
        this.fetchMenuList();
      }

      if (!copyFlag && id !== undefined) {
        if (!_isUndefined(id)) {
          queryLabel(id).then(function (res) {
            if (res && getResponse(res) && !_isEmpty(getResponse(res))) {
              _this2.setState({
                menuLabels: res
              });
            }
          });
        }
      }
    }
  }, {
    key: "getSnapshotBeforeUpdate",
    value: function getSnapshotBeforeUpdate(prevProps) {
      var _this$props2 = this.props,
          visible = _this$props2.visible,
          dataSource = _this$props2.dataSource,
          copyFlag = _this$props2.copyFlag;
      var code = dataSource.code;
      return visible && copyFlag && code !== (prevProps.dataSource || {}).code;
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState, snapshot) {
      // If we have a snapshot value, we've just added new items.
      // Adjust scroll so these new items don't push the old ones out of view.
      // (snapshot here is the value returned from getSnapshotBeforeUpdate)
      if (snapshot) {
        this.fetchMenuList();
      }
    }
  }, {
    key: "fetchMenuList",
    value: function fetchMenuList() {
      var _this3 = this;

      var _this$props3 = this.props,
          isSiteFlag = _this$props3.isSiteFlag,
          _this$props3$dataSour = _this$props3.dataSource,
          currentId = _this$props3$dataSour.currentId,
          level = _this$props3$dataSour.level,
          _this$props3$fetchCop = _this$props3.fetchCopyMenuList,
          fetchCopyMenuList = _this$props3$fetchCop === void 0 ? function (e) {
        return e;
      } : _this$props3$fetchCop;
      var params = {
        rootMenuId: currentId,
        // eslint-disable-next-line no-nested-ternary
        level: isSiteFlag ? level ? level.toUpperCase() : 'SITE' : 'ORGANIZATION'
      }; // fetchCopyMenuList(params).then(
      //   ({ copyMenuList = [], copyMenuListDefaultRowKeys = [], relatedRowKeys = [] }) => {
      //     this.setState({
      //       copyMenuList,
      //       menuSelectedRowKeys: copyMenuListDefaultRowKeys,
      //       relatedRowKeys,
      //     });
      //   }
      // );

      fetchCopyMenuList(params).then(function (res) {
        if (res) {
          _this3.setState({
            copyMenuList: res.copyMenuList,
            menuSelectedRowKeys: res.copyMenuListDefaultRowKeys,
            relatedRowKeys: res.relatedRowKeys
          });
        }
      });
    }
  }, {
    key: "cancel",
    value: function cancel() {
      var _this$props$onCancel = this.props.onCancel,
          onCancel = _this$props$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props$onCancel;
      var _this$state$dataSourc = this.state.dataSource,
          dataSource = _this$state$dataSourc === void 0 ? {} : _this$state$dataSourc;
      var _this$editForm$resetF = this.editForm.resetFields,
          resetFields = _this$editForm$resetF === void 0 ? function (e) {
        return e;
      } : _this$editForm$resetF;
      resetFields();
      this.setState({
        dataSource: _objectSpread(_objectSpread({}, dataSource), {}, {
          permissions: []
        }),
        permissionsSelectedRows: [],
        copyMenuList: [],
        menuSelectedRowKeys: []
      });
      onCancel();
    }
  }, {
    key: "save",
    value: function save() {
      var _this$props4 = this.props,
          _this$props4$handleSa = _this$props4.handleSave,
          handleSave = _this$props4$handleSa === void 0 ? function (e) {
        return e;
      } : _this$props4$handleSa,
          _this$props4$onCancel = _this$props4.onCancel,
          onCancel = _this$props4$onCancel === void 0 ? function (e) {
        return e;
      } : _this$props4$onCancel,
          dataSource = _this$props4.dataSource,
          siteLabelList = _this$props4.siteLabelList,
          tenantLabelList = _this$props4.tenantLabelList;
      var newDataSource = this.state.dataSource;
      var _this$editForm = this.editForm,
          _this$editForm$valida = _this$editForm.validateFields,
          validateFields = _this$editForm$valida === void 0 ? function (e) {
        return e;
      } : _this$editForm$valida,
          getFieldsValue = _this$editForm.getFieldsValue;
      validateFields(['type', 'level', 'parentId', 'name', 'route', 'icon', 'code'], function (err) {
        if (_isEmpty(err)) {
          var values = getFieldsValue();
          handleSave(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, dataSource), newDataSource), values), {}, {
            labels: (dataSource.level === 'site' ? siteLabelList : tenantLabelList).filter(function (item) {
              return values.labels.includes(item.name);
            }).map(function (item) {
              return _objectSpread(_objectSpread({}, item), {}, {
                labelId: item.id
              });
            }),
            virtualFlag: values.virtualFlag ? 1 : 0,
            codePrefix: values.codePrefix.slice(0, values.codePrefix.indexOf('.'))
          }), onCancel);
        }
      });
    }
  }, {
    key: "create",
    value: function create() {
      var _this4 = this;

      var _this$props5 = this.props,
          _this$props5$handleCr = _this$props5.handleCreate,
          handleCreate = _this$props5$handleCr === void 0 ? function (e) {
        return e;
      } : _this$props5$handleCr,
          dataSource = _this$props5.dataSource,
          siteLabelList = _this$props5.siteLabelList,
          tenantLabelList = _this$props5.tenantLabelList;
      var newDataSource = this.state.dataSource;
      var _this$editForm2 = this.editForm,
          _this$editForm2$valid = _this$editForm2.validateFields,
          validateFields = _this$editForm2$valid === void 0 ? function (e) {
        return e;
      } : _this$editForm2$valid,
          getFieldsValue = _this$editForm2.getFieldsValue;
      validateFields(['type', 'level', 'parentId', 'name', 'route', 'icon', 'code'], function (err) {
        if (!err) {
          var values = getFieldsValue();
          handleCreate(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, dataSource), values), newDataSource), {}, {
            labels: (dataSource.level === 'site' ? siteLabelList : tenantLabelList).filter(function (item) {
              return values.labels.includes(item.name);
            }).map(function (item) {
              return _objectSpread(_objectSpread({}, item), {}, {
                labelId: item.id
              });
            }),
            parentId: values.parentId,
            code: "".concat(values.codePrefix, ".").concat(values.code).toLowerCase(),
            virtualFlag: values.virtualFlag ? 1 : 0,
            codePrefix: values.codePrefix.slice(0, values.codePrefix.indexOf('.'))
          }), _this4.cancel.bind(_this4));
        }
      });
    } // 复制并创建菜单

  }, {
    key: "copyCreateMenu",
    value: function copyCreateMenu() {
      var _this5 = this;

      var _this$props6 = this.props,
          _this$props6$handleCo = _this$props6.handleCopyCreate,
          handleCopyCreate = _this$props6$handleCo === void 0 ? function (e) {
        return e;
      } : _this$props6$handleCo,
          dataSource = _this$props6.dataSource,
          siteLabelList = _this$props6.siteLabelList,
          tenantLabelList = _this$props6.tenantLabelList;
      var newDataSource = this.state.dataSource;
      var _this$editForm3 = this.editForm,
          _this$editForm3$valid = _this$editForm3.validateFields,
          validateFields = _this$editForm3$valid === void 0 ? function (e) {
        return e;
      } : _this$editForm3$valid,
          getFieldsValue = _this$editForm3.getFieldsValue;
      validateFields(['type', 'level', 'parentId', 'name', 'route', 'icon', 'code'], function (err) {
        if (!err) {
          var values = getFieldsValue();
          var organizationId = getCurrentOrganizationId();
          handleCopyCreate({
            copyMenuIds: _this5.state.menuSelectedRowKeys,
            rootMenu: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, dataSource), values), newDataSource), {}, {
              labels: (dataSource.level === 'site' ? siteLabelList : tenantLabelList).filter(function (item) {
                return values.labels.includes(item.name);
              }).map(function (item) {
                return _objectSpread(_objectSpread({}, item), {}, {
                  labelId: item.id
                });
              }),
              parentId: values.parentId,
              code: "".concat(values.codePrefix, ".").concat(values.code).toLowerCase(),
              virtualFlag: values.virtualFlag ? 1 : 0,
              codePrefix: values.codePrefix.slice(0, values.codePrefix.indexOf('.')),
              tenantId: organizationId
            })
          }, _this5.cancel.bind(_this5));
        }
      });
    }
  }, {
    key: "addPermissions",
    value: function addPermissions() {
      var _this6 = this;

      var _this$props$handleQue = this.props.handleQueryPermissions,
          handleQueryPermissions = _this$props$handleQue === void 0 ? function (e) {
        return e;
      } : _this$props$handleQue;
      var _this$editForm$getFie = this.editForm.getFieldsValue,
          getFieldsValue = _this$editForm$getFie === void 0 ? function (e) {
        return e;
      } : _this$editForm$getFie;

      var _getFieldsValue = getFieldsValue(),
          level = _getFieldsValue.level;

      if (!_isEmpty(level)) {
        this.setState({
          permissionsModalVisible: true
        });
        handleQueryPermissions({
          level: level,
          page: 0,
          size: 10
        }).then(function (res) {
          if (res) {
            var dataSource = res.dataSource,
                pagination = res.pagination;
            var _this6$state$permissi = _this6.state.permissionsModalDataSource,
                permissionsModalDataSource = _this6$state$permissi === void 0 ? [] : _this6$state$permissi;

            _this6.setState({
              permissionsModalDataSource: _uniqBy(dataSource.concat(permissionsModalDataSource), 'id'),
              permissionsModalPagination: pagination
            });
          }
        });
      }
    }
  }, {
    key: "closePermissionsModal",
    value: function closePermissionsModal() {
      this.setState({
        permissionsModalVisible: false,
        permissionsModalDataSource: [],
        permissionsModalPagination: {}
      });
    }
  }, {
    key: "onPermissionsModalOk",
    value: function onPermissionsModalOk(selectedRows) {
      // const { dispatch } = this.props;
      var dataSource = this.state.dataSource;
      this.setState({
        dataSource: _objectSpread(_objectSpread({}, dataSource), {}, {
          permissions: _uniqBy(dataSource.permissions.concat(selectedRows), 'id')
        })
      });
      this.setState({
        permissionsModalVisible: false,
        permissionsModalDataSource: [],
        permissionsModalPagination: {}
      });
    }
  }, {
    key: "onPermissionsSelect",
    value: function onPermissionsSelect(record, selected) {
      var _this$state$permissio = this.state.permissionsSelectedRows,
          permissionsSelectedRows = _this$state$permissio === void 0 ? [] : _this$state$permissio;
      this.setState({
        permissionsSelectedRows: selected ? permissionsSelectedRows.concat(record) : permissionsSelectedRows.filter(function (n) {
          return n.id !== record.id;
        })
      });
    }
  }, {
    key: "onPermissionsSelectAll",
    value: function onPermissionsSelectAll(selected, newSelectedRows, changeRows) {
      var _this$state$permissio2 = this.state.permissionsSelectedRows,
          permissionsSelectedRows = _this$state$permissio2 === void 0 ? [] : _this$state$permissio2;
      this.setState({
        permissionsSelectedRows: selected ? permissionsSelectedRows.concat(changeRows) : _pullAllBy(_toConsumableArray(permissionsSelectedRows), changeRows, 'id')
      });
    }
  }, {
    key: "deletePermissions",
    value: function deletePermissions() {
      var _this$state = this.state,
          _this$state$permissio3 = _this$state.permissionsSelectedRows,
          permissionsSelectedRows = _this$state$permissio3 === void 0 ? [] : _this$state$permissio3,
          dataSource = _this$state.dataSource;
      this.setState({
        dataSource: _objectSpread(_objectSpread({}, dataSource), {}, {
          permissions: _pullAllBy(_toConsumableArray(dataSource.permissions), permissionsSelectedRows, 'id')
        })
      });
    }
  }, {
    key: "openIconModal",
    value: function openIconModal() {
      this.setState({
        iconsModalVisible: true
      });
    }
  }, {
    key: "onIconSelect",
    value: function onIconSelect(icon) {
      var _this$editForm$setFie = this.editForm.setFieldsValue,
          setFieldsValue = _this$editForm$setFie === void 0 ? function (e) {
        return e;
      } : _this$editForm$setFie;
      setFieldsValue({
        icon: icon
      });
      this.setState({
        iconsModalVisible: false
      });
    }
  }, {
    key: "closeIconsModal",
    value: function closeIconsModal() {
      this.setState({
        iconsModalVisible: false
      });
    }
  }, {
    key: "handleTypeChange",
    value: function handleTypeChange(type) {
      var _this$editForm$setFie2 = this.editForm.setFields,
          setFields = _this$editForm$setFie2 === void 0 ? function (e) {
        return e;
      } : _this$editForm$setFie2;
      var dataSource = this.state.dataSource;
      setFields({
        dir: {
          error: undefined
        },
        code: {
          value: undefined,
          error: undefined
        },
        name: {
          value: undefined,
          error: undefined
        },
        parentId: {
          value: undefined,
          error: undefined
        },
        route: {
          value: undefined,
          error: undefined
        }
      });
      this.setState({
        dataSource: _objectSpread(_objectSpread({}, dataSource), {}, {
          type: type,
          permissions: []
        })
      });
    }
  }, {
    key: "setDataSource",
    value: function setDataSource() {
      var newDataSource = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
      var dataSource = this.state.dataSource;
      this.setState({
        dataSource: _objectSpread(_objectSpread({}, dataSource), newDataSource)
      });
    }
  }, {
    key: "handlePermissionsTableChange",
    value: function handlePermissionsTableChange(params) {
      var _this7 = this;

      var _this$props$handleQue2 = this.props.handleQueryPermissions,
          handleQueryPermissions = _this$props$handleQue2 === void 0 ? function (e) {
        return e;
      } : _this$props$handleQue2;
      var _this$editForm$getFie2 = this.editForm.getFieldsValue,
          getFieldsValue = _this$editForm$getFie2 === void 0 ? function (e) {
        return e;
      } : _this$editForm$getFie2;

      var _getFieldsValue2 = getFieldsValue(),
          level = _getFieldsValue2.level;

      handleQueryPermissions(_objectSpread({
        level: level,
        page: 0,
        size: 10
      }, params)).then(function (res) {
        if (res) {
          var dataSource = res.dataSource,
              pagination = res.pagination;

          _this7.setState({
            permissionsModalDataSource: dataSource,
            permissionsModalPagination: pagination
          });
        }
      });
    }
    /**
     * 选中或取消复制的内容的菜单
     * @param {object} record - 当前行数据
     * @param {boolean} selected - 是否选中
     */

  }, {
    key: "handleMenuRowSelect",
    value: function handleMenuRowSelect(record, selected) {
      var dataSource = this.props.dataSource;
      var _this$state2 = this.state,
          menuSelectedRowKeys = _this$state2.menuSelectedRowKeys,
          relatedRowKeys = _this$state2.relatedRowKeys;
      var setIdList = [];
      if (record.id === dataSource.currentId) return; // 复制的节点必须勾选,不可取消
      // 子节点被勾选时，其父节点若未被勾选，则自动被勾选
      // 节点的被动勾选，不会触发勾选其所有子节点的逻辑，反之，则会勾选所有子节点

      var addParentIdList = function addParentIdList(parentId) {
        var isIncludeParent = menuSelectedRowKeys.includes(parentId);

        if (!isIncludeParent) {
          setIdList.push(parentId);
          var targetParentRow = relatedRowKeys.find(function (item) {
            return item.id === parentId;
          });

          if (!_isUndefined(targetParentRow)) {
            addParentIdList(targetParentRow.parentId);
          }
        }
      };

      var getSubSetIdList = function getSubSetIdList() {
        var collections = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        collections.forEach(function (n) {
          setIdList.push(n.id);

          if (!_isEmpty(n.subMenus)) {
            getSubSetIdList(n.subMenus);
          }
        });
      };

      if (!_isEmpty(record.subMenus)) {
        getSubSetIdList(record.subMenus);
      }

      if (selected) {
        addParentIdList(record.parentId);
      }

      setIdList.push(record.id);

      var filteredRowKeys = _filter(menuSelectedRowKeys, function (item) {
        return !setIdList.includes(item);
      });

      this.setState({
        menuSelectedRowKeys: selected ? menuSelectedRowKeys.concat(setIdList) : filteredRowKeys
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this8 = this;

      var _this$props7 = this.props,
          path = _this$props7.path,
          visible = _this$props7.visible,
          _this$props7$processi = _this$props7.processing,
          processing = _this$props7$processi === void 0 ? {} : _this$props7$processi,
          _this$props7$handleCh = _this$props7.handleCheckMenuDirExists,
          handleCheckMenuDirExists = _this$props7$handleCh === void 0 ? function (e) {
        return e;
      } : _this$props7$handleCh,
          _this$props7$levelCod = _this$props7.levelCode,
          levelCode = _this$props7$levelCod === void 0 ? [] : _this$props7$levelCod,
          _this$props7$handleQu = _this$props7.handleQueryDir,
          handleQueryDir = _this$props7$handleQu === void 0 ? function (e) {
        return e;
      } : _this$props7$handleQu,
          _this$props7$menuPref = _this$props7.menuPrefixList,
          menuPrefixList = _this$props7$menuPref === void 0 ? [] : _this$props7$menuPref,
          menuTypeList = _this$props7.menuTypeList,
          _this$props7$recordCr = _this$props7.recordCreateFlag,
          recordCreateFlag = _this$props7$recordCr === void 0 ? false : _this$props7$recordCr,
          _this$props7$copyFlag = _this$props7.copyFlag,
          copyFlag = _this$props7$copyFlag === void 0 ? false : _this$props7$copyFlag,
          propsDataSource = _this$props7.dataSource,
          siteLabelList = _this$props7.siteLabelList,
          tenantLabelList = _this$props7.tenantLabelList;
      var typePrompt = {
        dir: intl.get("".concat(viewMessagePrompt, ".menu.dir")).d('目录'),
        menu: intl.get("".concat(viewMessagePrompt, ".menu.menu")).d('菜单'),
        root: intl.get("".concat(viewMessagePrompt, ".menu.root")).d('预置目录'),
        link: intl.get("".concat(viewMessagePrompt, ".menu.link")).d('链接')
      };
      var _this$state3 = this.state,
          stateDataSource = _this$state3.dataSource,
          permissionsModalDataSource = _this$state3.permissionsModalDataSource,
          permissionsModalPagination = _this$state3.permissionsModalPagination,
          permissionsModalVisible = _this$state3.permissionsModalVisible,
          iconsModalVisible = _this$state3.iconsModalVisible,
          menuSelectedRowKeys = _this$state3.menuSelectedRowKeys,
          copyMenuList = _this$state3.copyMenuList,
          menuLabels = _this$state3.menuLabels;
      var filteredMenuTypeList = menuTypeList.filter(function (item) {
        return item.value !== 'ps';
      });

      var dataSource = _objectSpread(_objectSpread({
        type: recordCreateFlag ? 'dir' : 'root'
      }, stateDataSource), propsDataSource); // eslint-disable-next-line no-nested-ternary


      var title = copyFlag ? intl.get("".concat(viewMessagePrompt, ".title.copyCreate")).d('复制并创建') : dataSource.id !== undefined ? intl.get("".concat(viewMessagePrompt, ".title.editWithParam"), {
        name: typePrompt[dataSource.type]
      }).d("\u7F16\u8F91".concat(typePrompt[dataSource.type])) : intl.get("".concat(viewMessagePrompt, ".title.createWithParam"), {
        name: typePrompt[dataSource.type || 'dir']
      }).d("\u521B\u5EFA".concat(typePrompt[dataSource.type || 'dir']));
      var organizationId = getCurrentOrganizationId(); // const userInfo = getCurrentUser();

      var drawerProps = {
        title: title,
        visible: visible,
        mask: true,
        maskStyle: {
          backgroundColor: 'rgba(0,0,0,.85)'
        },
        placement: 'right',
        destroyOnClose: true,
        onClose: this.cancel.bind(this),
        width: 620
      };
      var formProps = {
        path: path,
        recordCreateFlag: recordCreateFlag,
        copyFlag: copyFlag,
        menuPrefixList: menuPrefixList,
        menuTypeList: filteredMenuTypeList,
        menuLabels: menuLabels,
        siteLabelList: siteLabelList,
        tenantLabelList: tenantLabelList,
        ref: function ref(_ref) {
          _this8.editForm = _ref;
        },
        organizationId: organizationId,
        handleCheckMenuDirExists: handleCheckMenuDirExists,
        dataSource: _objectSpread({
          level: 'site'
        }, dataSource),
        levelCode: levelCode.filter(function (o) {
          return o.value !== 'org';
        }),
        editable: dataSource.id !== undefined,
        dirModalLoading: processing.queryDir,
        handleQueryDir: handleQueryDir,
        handleTypeChange: this.handleTypeChange.bind(this),
        handleOpenIconModal: this.openIconModal.bind(this),
        handleSetDataSource: this.setDataSource.bind(this)
      }; // const tableProps = {
      //   dataSource: dataSource.permissions,
      //   pagination: {
      //     showSizeChanger: true,
      //     pageSizeOptions: ['10', '20', '50', '100'],
      //     pageSize: 10,
      //     total: (dataSource.permissions || []).length,
      //     showTotal: totalRender,
      //   },
      //   rowSelection: {
      //     selectedRowKeys: permissionsSelectedRows.map(n => n.id),
      //     onSelect: this.onPermissionsSelect.bind(this),
      //     onSelectAll: this.onPermissionsSelectAll.bind(this),
      //   },
      // };

      var permissionsModalProps = {
        visible: permissionsModalVisible,
        dataSource: permissionsModalDataSource,
        pagination: permissionsModalPagination,
        onCancel: this.closePermissionsModal.bind(this),
        onOk: this.onPermissionsModalOk.bind(this),
        handleFetchData: this.handlePermissionsTableChange.bind(this),
        loading: processing.queryPermissions || false,
        selectedRows: dataSource.permissions
      };
      var iconsModalProps = {
        visible: iconsModalVisible,
        onSelect: this.onIconSelect.bind(this),
        onCancel: this.closeIconsModal.bind(this)
      };
      var rowSelection = {
        selectedRowKeys: menuSelectedRowKeys,
        onSelect: this.handleMenuRowSelect.bind(this)
      };
      var tableProps = {
        menuTypeList: menuTypeList,
        dataSource: copyMenuList,
        loading: processing.queryCopyMenu,
        rowSelection: rowSelection,
        defaultExpandedRowKeys: menuSelectedRowKeys
      };
      return /*#__PURE__*/React.createElement(Drawer, drawerProps, /*#__PURE__*/React.createElement("div", {
        className: styles['ciam-menu-config-editor']
      }, /*#__PURE__*/React.createElement(EditorForm, formProps), copyFlag && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Divider, {
        orientation: "left"
      }, intl.get("".concat(viewMessagePrompt, ".title.copyMenu")).d('选择复制内容')), /*#__PURE__*/React.createElement(CopyMenuTable, tableProps)), /*#__PURE__*/React.createElement("br", null)), /*#__PURE__*/React.createElement("div", {
        style: {
          position: 'absolute',
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e8e8e8',
          padding: '10px 16px',
          textAlign: 'right',
          left: 0,
          background: '#fff',
          borderRadius: '0 0 4px 4px',
          zIndex: 100
        }
      }, /*#__PURE__*/React.createElement(Button, {
        onClick: this.cancel.bind(this),
        disabled: processing.save || processing.create,
        style: {
          marginRight: 8
        }
      }, intl.get("".concat(commonPrompt, ".button.cancel")).d('取消')), copyFlag ? /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        loading: processing.copyCreate,
        onClick: this.copyCreateMenu.bind(this)
      }, intl.get("".concat(commonPrompt, ".button.ok")).d('确定')) : dataSource.id !== undefined ? /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        loading: processing.save,
        onClick: this.save.bind(this)
      }, intl.get("".concat(commonPrompt, ".button.save")).d('保存')) : /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        loading: processing.create,
        onClick: this.create.bind(this)
      }, intl.get("".concat(commonPrompt, ".button.ok")).d('确定'))), /*#__PURE__*/React.createElement(Permissions, permissionsModalProps), /*#__PURE__*/React.createElement(IconsModal, iconsModalProps));
    }
  }], [{
    key: "getDerivedStateFromProps",
    value: function getDerivedStateFromProps(nextProps, prevState) {
      return nextProps.dataSource.id !== prevState.dataSource.id ? {
        dataSource: nextProps.dataSource
      } : null;
    }
  }]);

  return Editor;
}(PureComponent);

export { Editor as default };